<template>
  <page class="home">
    <page-header>
      <x-header :left-options="{showBack: false}">首页</x-header>
    </page-header>
    <page-content :scroll="false">
      <div class="nav grid">
        <div class="nav-c grid-item">
          <div class="ico">
            <i class="iconfont icon-saomiao"></i>
          </div>
          <p class="text">扫一扫</p>
        </div>
        <router-link class="nav-c grid-item" :to="{path:'/device'}">
          <div class="ico">
            <i class="iconfont icon-yingyongchengxu" style="color: #fff;"></i>
          </div>
          <p class="text">设备管理</p>
        </router-link>
        <router-link class="nav-c grid-item" :to="{path:'/taskfinish'}">
          <div class="ico">
            <i class="icon iconfont icon-qianshoushenpitongguo-xianxing" style="color: #fff;"></i>
          </div>
          <p class="text">已办任务</p>
        </router-link>
      </div>
      <section class="grid">
        <router-link class="grid-item" :to="{path:'/apply'}">
          <div class="ico">
            <i class="iconfont icon-danju" style="color: #ff9400;"></i>
          </div>
          <p class="text">调拨单管理</p>
        </router-link>
        <router-link class="grid-item" :to="{path:'/echarts'}">
          <div class="ico">
            <i class="iconfont icon-tiaoxingtu" style="color: #3f8fdb;"></i>
          </div>
          <p class="text">设备使用率</p>
        </router-link>
        <router-link class="grid-item" :to="{path:'/task?actNode=d_shouhuo'}">
          <div class="ico">
            <i class="iconfont icon-baoguofahuo" style="color: #998bb6;"></i>
          </div>
          <div class="badge" v-if="dfhList">{{dfhList}}</div>
          <p class="text">待发货</p>
        </router-link>
        <router-link class="grid-item" :to="{path:'/task?actNode=qr_fahuo'}">
          <div class="ico">
            <i class="iconfont icon-yunshuzhongwuliu" style="color: #45a8ee;"></i>
          </div>
          <div class="badge" v-if="qrfhList">{{qrfhList}}</div>
          <p class="text">待确认发货</p>
        </router-link>
        <router-link class="grid-item" :to="{path:'/task?actNode=d_shouhuo'}">
          <div class="ico">
            <i class="iconfont icon-chaibaoguoqujian" style="color: #e37b65;"></i>
          </div>
          <div class="badge" v-if="dshList">{{dshList}}</div>
          <p class="text">待收货</p>
        </router-link>
        <router-link class="grid-item" :to="{path:'/task?actNode=qr_shouhuo'}">
          <div class="ico">
            <i class="iconfont icon-zhengquewancheng-yuankuang" style="color: #00ae90;"></i>
          </div>
          <div class="badge" v-if="qrshList">{{qrshList}}</div>
          <p class="text">待确认收货</p>
        </router-link>
      </section>
    </page-content>
    <page-footer>
      <x-footer></x-footer>
    </page-footer>
  </page>
</template>

<script>
import { XHeader } from 'vux'
import { mapGetters } from 'vuex'
import { com } from '@service'
import XFooter from '@components/common/Footer'

export default {
  name: 'Home',
  components: {
    XHeader,
    XFooter
  },
  computed: {
    ...mapGetters({
      userInfo: 'user/info',
      token: 'user/token'
    })
  },
  data () {
    return {
      qrshList: '',
      dqrwzList: '',
      dqrdbList: '',
      qrfhList: '',
      dtdbdList: '',
      dshList: '',
      dqrlxList: '',
      dfhList: ''
    }
  },
  mounted () {
    this.loadData()
  },
  methods: {
    async loadData () {
      let token = this.token
      let userId = this.userInfo.id
      try {
        let data = await com.goToIndex({ userId, token })
        let items = [
          'qrshList',
          'dqrwzList',
          'dqrdbList',
          'qrfhList',
          'dtdbdList',
          'dshList',
          'dqrlxList',
          'dfhList'
        ]
        items.forEach((key) => {
          this[key] = data[key].length
        })
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;

  .nav {
    width: 100%;
    height: 6.5rem;
    background: #1e82d2;

    &.grid {
      grid-template-columns: 1fr 1fr 1fr;
      background: #1e82d2;
    }
    .nav-c.grid-item {
      background: #1e82d2;
      position: relative;

      .text{
        color: #fff;
      }
    }
  }

  .grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    background: #fff;

    .grid-item {
      position: relative;
      display: flex;
      flex-flow: column;
      align-items: center;
      background: #fff;

      .ico {
        width: 2rem;
        height: 2rem;
        margin: 1rem;
      }
      .text {
        line-height: 1.6rem;
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
        color: #333;
      }
      .badge {
        position: absolute;
        right: 1rem;
        top: 0.5rem;
        width: 1rem;
        height: 1rem;
        text-align: center;
        line-height: 1rem;
        border-radius: 50%;
        font-size: 0.8rem;
        background: #ee6337;
        color: #fff;
      }
    }
  }

  .iconfont {
    font-size: 2rem;
    color: #fff;
  }
}
</style>
